package org.pockito.dctmpersistence.mock;

import java.util.Date;

import com.documentum.fc.client.IDfType;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfId;
import com.documentum.fc.common.IDfId;
import com.documentum.fc.common.IDfTime;
import com.documentum.fc.common.IDfValue;

public class DfValue implements IDfValue {

	public DfValue(Object value) {
		this(value, IDfType.DF_UNDEFINED);
	}

	public DfValue(Object value, int type) {
		super();
		this.value = value;
		this.type = type;
	}

	private Object value;
	private int type;
	
	public boolean asBoolean() {
		return (Boolean) value;
	}

	public double asDouble() {
		return (Double) value;
	}

	public IDfId asId() {
		if (value.getClass().isAssignableFrom(IDfId.class)) {
			return (IDfId) value;
		} else {
			IDfId idValue = new DfId((String) value);
			return idValue;
		}
	}

	public int asInteger() {
		return (Integer) value;
	}

	public String asString() {
		return (String) value;
	}

	public IDfTime asTime() {
		if (value.getClass().isAssignableFrom(Date.class)) {
			return new DfTime((Date)value);
		} else {
			return new DfTime(value.toString());
		}
	}

	public int compareTo(IDfValue arg0) throws DfException {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getDataType() {
		return type;
	}
	
	@Override
	public String toString() {
		return value.toString();
	}

}
